package hit.persistence;

import static org.junit.Assert.*;

import java.io.File;

import hit.core.HomeInventoryTracker;
import hit.core.StorageUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class PersistenceTest {
	HomeInventoryTracker hit;
	File saveFile;
	
	@Before
	public void setUp() {
		hit = HomeInventoryTracker.Instance();
		hit.AddStorageUnit(new StorageUnit("test"));
		
		saveFile = new File("save.dat");
	}
	
	@After
	public void tearDown() {
		hit = null;
	}
	
	@Test 
	public void testPersistence() {
		//try saving and reading
		SerializationHandler.saveData(hit, saveFile);
		HomeInventoryTracker result = SerializationHandler.loadData(saveFile);
		
		//test loading an invalid file
		result = SerializationHandler.loadData(new File("bogus.txt"));
		assertEquals(result, null);
	}
}
